<?php

namespace app\common\model;

use think\facade\Cache;
use think\Model;

class PropsModel extends Model
{
    // 类型
    const TYPE_CATE = [
        1 => '挂件',
        2 => '弹幕背景',
        3 => '字体',
    ];

    protected static function init()
    {
        static::afterUpdate(function ($user) {
            Cache::rm('props_list');
        });
    }

    public static function getTypeTextAttr($value, $data)
    {
        return isset(self::TYPE_CATE[$data['type']]) ? self::TYPE_CATE[$data['type']] : '';
    }

    public static function lists(): array
    {
        return Cache::remember('props_list', function () {
            return array_column(static::select()->toArray(), null, 'id');
        });
    }
}